package com.xiaohui.user.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohui.entity.PageResult;
import com.xiaohui.user.entity.dto.UserDto;
import com.xiaohui.user.entity.po.UserPo;
import com.xiaohui.user.dao.UserMapper;
import com.xiaohui.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Integer addUser(UserDto userDto) {
        UserPo po = new UserPo();
        BeanUtils.copyProperties(userDto, po);
        return userMapper.insert(po);
    }

    @Override
    public Integer delete(Long id) {
        int i = 1/0;
        return userMapper.deleteById(id);
    }

    @Override
    public PageResult<UserPo> selectByPage(UserDto userDto) {
         IPage<UserPo> userPoPage  = new Page<>(userDto.getPageNum(), userDto.getPageSize());
        IPage<UserPo> page = userMapper.selectByPage(userPoPage);
        PageResult<UserPo> result = new PageResult<>();
        result.loadData(page);
        return result;
    }
}
